import {
  request,
  makePhoneCallHandler
} from '../../utils/requestUtils';

import {
  userBehavior
} from '../../behaviors/userBehavior'

Page({
  behaviors: [userBehavior],
  data: {
    show: false, // 期望送达日期弹框
    minDate: new Date().getTime(),
    currentDate: new Date().getTime(),
    form: {
      customerName: '',
      contact: '',
      payableAmount: '0',
      deliveryDate: '', //送达日期
      deliveryStr: '', //送达时间点
      remark: '',
      addrId: '', //地址id
      lines: [], //行信息
    },
    addr: {
      id: '',
    }
  },
  onShow() {


  },


  onLoad(options) {
    console.log('options', options)
    if (options.id) {
      this.getOrderById(options.id)
    }
  },


      //拨打电话
  async makeCustomerPhoneCall(){
    let result = await makePhoneCallHandler(this.data.form.addr.contactPhone)
  },
  

  //获取订单信息
  async getOrderById(id) {
    const result = await request({
      url: `/merchant/order/rider/` + id,
      method: "GET",
      data: {}
    })
    if (result.data.code == 200) {
      this.setData({
        form: result.data.data
      })
    }
  },
   // 出货 4;完成 6
   async operate(event){
     console.log('event', event)
     if(event.target.dataset.type == 4){
      const modalRes = await wx.showModal({
        content: '确定备货完成 ?'
      })
      if (modalRes.cancel) return
      const result = await request({
        url: `/merchant/order/api/updateStatus`,
        method: "PUT",
        data:{
          id: this.data.form.id
        }
      })
      if (result.data.code == 200) {
        this.getOrderById(this.data.form.id)
      }
     }else if(event.target.dataset.type == 6){
      const modalRes = await wx.showModal({
        content: '确定客户已取货 ?'
      })
      const result = await request({
        url: `/merchant/order/api/finish`,
        method: "PUT",
        data:{
          id: this.data.form.id
        }
      })
      if (result.data.code == 200) {
        this.getOrderById(this.data.form.id)
      }
     }
  
  },
  // 返回上一步
  onScrollRefresh(){
    wx.navigateBack({
      delta: 1
    })
  }
})